<?php

require_once(dirname(__DIR__) . '/api/DB.php');
require_once(dirname(__DIR__) . '/api/response.php');
require_once(dirname(__DIR__) . '/api/func.php');

try {

    $db = new DB();
    $pdo = $db::$pdo;

    if (!isset($_GET['user_id'])) {
        throw new Exception(fieldMap('user_id') . '为必传项');
    }

    if (empty($_GET['user_id'])) {
        throw new Exception(fieldMap('user_id') . '不能为空');
    }

    // 查询用户详情
    $sql = 'select * from users where id = ?';
    $stmt = $pdo->prepare($sql);
    $stmt->execute([$_GET['user_id']]);
    $res = $stmt->fetch(PDO::FETCH_ASSOC);
    if (empty($res)) {
        throw new Exception('用户不存在');
    }

    myResponse('', 1, 200, $res);
} catch (Exception $e) {
    myResponse($e->getMessage(), 0, 200);
}